<template>
  <div class="shade" @click="closeSearchDialog"></div>
  <div class="ground-glass search-container">
    <div class="search-title">搜索</div>
    <div class="search-bz">输入姓名查找所在办公室及固定资产</div>
    <div class="search-input">
      <input
        type="text"
        placeholder="请输入姓名或首字母"
        v-model="searchName"
      />
      <button @click="handleClick">搜索</button>
    </div>
    <div class="content-container">
      <div class="content-box"></div>
    </div>
  </div>
</template>

<script setup>
import { ref } from "vue";
import { searchUser } from "@/api/index";
const emit = defineEmits(["closeSearch"]);
const searchName = ref("");
const userList = ref([]);
// 验证姓名是否为中文
const chineseNameRegex = /^[\u4e00-\u9fa5]{2,}$/;
function handleClick() {
  if (searchName.value == "") {
    alert("请输入姓名或首字母");
    return;
  }
  searchUser(searchName.value).then(({ data: res }) => {
    if (res.code == 0) {
      if (res.data.total !== 1) {
        userList.value = res.data.list;
      }
    }
  });
  // else if (!chineseNameRegex.test(searchName.value)) {
  //   alert("请输入正确的中文姓名");
  //   return;
  // }
}
function closeSearchDialog() {
  emit("closeSearch");
}
</script>

<style scoped lang="less">
.search-container {
  z-index: 10000;
  padding: 20px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: all 0.3s ease;
  width: 500px;
  height: 520px;
  .search-title {
    font-size: 30px;
    font-weight: bolder;
  }
  .search-bz {
    margin-top: 20px;
    font-size: 18px;
    font-weight: bold;
    color: #999;
  }
  .search-input {
    margin-top: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    input {
      width: 350px;
      height: 40px;
      padding: 0 10px;
      border: 1px solid #ccc;
      border-radius: 5px;
      font-size: 16px;
      background-color: rgba(0, 0, 0, 0.027);
    }
    button {
      width: 100px;
      height: 40px;
      border: none;
      border-radius: 5px;
      background-color: #6366f1;
      color: #fff;
      font-size: 16px;
      cursor: pointer;
    }
  }
  .content-container {
    margin-top: 20px;
    width: 100%;
    height: 325px;
    background-color: rgba(0, 0, 0, 0.027);
    border-radius: 5px;
    .content-box {
      width: 100%;
      display: flex;
      flex-direction: column;
      .user-list {
        width: 100%;
        padding: 5px;
        display: flex;
      }
    }
  }
}
</style>
